var PRIMARY_PATH = "";
var BASE_PATH = "";

function setPath(path,basePath){
	PRIMARY_PATH = path;
	BASE_PATH = basePath;
}

$(function() {
	$("#securType").select2();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    
    initValidateForm();
    
    var method = $("#method").val();
	if("detail" == method){
		$("#invesSecurAddForm input,select").attr("readonly","readonly");
		$("#invesSecurAddForm input,select").attr("disabled","disabled");
		$("#invesSecurAddForm input").css("cursor","default");
	}
});

function initValidateForm() {
	$("#invesSecurAddForm").validate({
		focusCleanup : true,
		rules : {
			'securCode' : {
				required : true
			},
			'securName' : {
				required : true
			},
			'securType' : {
				required : true
			},
			'securTotalShare' : {
				required : true,
				number : true
			},
			'shareSumProportion' : {
				required : true,
				number : true
			},
			'shareSingleProportion' : {
				required : true,
				number : true
			},
			'securFilePath' : {
				required : true
			},
			'purchaseLimit' : {
				required : true,
				number : true
			},
			'subscribeLimit' : {
				required : true,
				number : true
			},
			'minSubscribeShare' : {
				required : true,
				number : true
			}
		},
		messages : {
			'securCode' : {
				required : "标的代码不能为空"
			},
			'securName' : {
				required : "标的名称不能为空"
			},
			'securType' : {
				required : "标的类型不能为空"
			},
			'securTotalShare' : {
				required : "标的总份额不能为空",
				number : "标的总份额请输入数字"
			},
			'shareSumProportion' : {
				required : "份额合计可投资比例不能为空",
				number : "份额合计可投资比例请输入数字"
			},
			'shareSingleProportion' : {
				required : "份额单产品可投资比例不能为空",
				number : "份额单产品可投资比例请输入数字"
			},
			'securFilePath' : {
				required : "标的净值文件位置不能为空"
			},
			'purchaseLimit' : {
				required : "标的申购上限不能为空",
				number : "标的申购上限请输入数字"
			},
			'subscribeLimit' : {
				required : "标的认购上限不能为空",
				number : "标的认购上限请输入数字"
			},
			'minSubscribeShare' : {
				required : "标的最小认购额不能为空",
				number : "标的最小认购额请输入数字"
			}
		}
	});
}

function doSubmit(){
	var form = $('#invesSecurAddForm');
	if(false === form.valid()){
		toastr.warning("请完善信息");
		return;
	}
	var method = $("#method").val();
	if("update" == method){
		$('#invesSecurAddForm').attr("action", BASE_PATH+"business/invesSecur/updateInvesSecur.do")
	}
	//提交表单
	SubmitAndPreventSecond("invesSecurAddForm",true);
}